package com.situ.day22.annotation;

import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Arrays;

//@Author("/author")
@Author(value = "/author")
public class AuthorDemo {
    @Author
    private String str;

    @Author(name = "张三", age = 23, value = {"男", "女"})
    //@Author(name = "张三")
    public void save() {

    }

    @Test
    public void test1() throws NoSuchMethodException {
        Class<AuthorDemo> clazz = AuthorDemo.class;
        Author typeAuthor = clazz.getAnnotation(Author.class);
        System.out.println(typeAuthor.value()[0]);///author

        // 1.先获取代表方法的Method类型
        Method method = clazz.getMethod("save");
        Author methodAuthor = method.getAnnotation(Author.class);
        //// 2、获取方法上的注解
        System.out.println(methodAuthor.name());//张三
        System.out.println(methodAuthor.age());//23
        System.out.println(Arrays.toString(methodAuthor.value()));//[男, 女]
    }
}
